package android_rteditor.customsortricheditor.editor;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import org.greenrobot.eventbus.EventBus;

import android_rteditor.customsortricheditor.R;
import android_rteditor.customsortricheditor.event.EventCenter;

/**
 * 音频视图
 *
 * @author panxiaodong01
 * @since 2017/9/11
 */

public class RichAudio extends LinearLayout implements IEditorItem, View.OnClickListener {

    private ImageView playState;
    private ImageView playClose;
    private ProgressBar playProgress;
    private TextView playDuration;

    public RichAudio(Context context) {
        super(context);
        init();
    }

    public RichAudio(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public RichAudio(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.audio_view, null);
        playState = (ImageView) view.findViewById(R.id.play_state);
        playClose = (ImageView) view.findViewById(R.id.play_close);
        playProgress = (ProgressBar) view.findViewById(R.id.play_percent);
        playDuration = (TextView) view.findViewById(R.id.play_duration);
        playState.setOnClickListener(this);
        playClose.setOnClickListener(this);
        ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 140);
        addView(view, lp);

    }

    @Override
    public View getView() {
        return this;
    }

    @Override
    public int getType() {
        return EditorItemFactory.EDITOR_ITEM_AUDIO;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.play_state:

                break;

            case R.id.play_close:
                EventCenter.AudioDeleteEvent deleteEvent = new EventCenter.AudioDeleteEvent();
                deleteEvent.mRichAudio = this;
                EventBus.getDefault().post(deleteEvent);
                break;

            default:
                break;
        }
    }
}
